package news.web;

import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import news.model.Comment;
import news.model.CommonResult;
import news.model.News;
import news.model.NewsType;
import news.service.CommentService;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(tags = "评论管理")
@RestController
@RequestMapping(path = "admin/comment")
public class CommentController {
    @Autowired(required = false)
    CommentService commentService;

    //查询所有的评论并分页
    @ApiOperation(value = "查询所有评论")
    @GetMapping("/comments")
    public CommonResult newsTypes(@RequestBody Comment comment) {
        PageInfo<Comment> comments = commentService.commentList(comment);
        comments.getList();
        comments.getTotal();
        CommonResult commonResult = new CommonResult(200, comments, "查询成功");
        return commonResult;
    }

    //删除
    @ApiOperation(value = "删除评论")
    @GetMapping("/delete")
    public CommonResult delete(Integer id){
        commentService.delete(id);
        CommonResult commonResult = new CommonResult(200,"删除成功！");
        return  commonResult;
    }

    //改状态
    @ApiOperation(value = "修改评论状态")
    @GetMapping("/changeS")
    public CommonResult changeS(Integer id,Integer status){
        commentService.changeS(id,status);
        CommonResult commonResult = new CommonResult(200,"修改状态成功！");
        return  commonResult;
    }


}
